VERSION = 0.1
PREFIX = lib
APP_NAME = gluco_app
SUFIX = .so.$(VERSION)
BINARY_NAME = $(PREFIX)$(APP_NAME)$(SUFIX)
ARCH = i686
CC = gcc
SRC_EXTENSION = c
.SUFFIXES = .o .$(SRC_EXTENSION)
SHELL=/bin/bash
SOURCES_DIR = $(shell cd ../src && dirs -l)
RESOURCES_DIR = $(shell cd ../resources && dirs -l)
SCRIPTS_DIR = $(shell cd ../scripts && dirs -l)
SOURCES = $(shell cd $(SOURCES_DIR) && ls *.$(SRC_EXTENSION))
CONFIG_NAME = debug
MODE = -g
OBJECTS = $(SOURCES:.$(SRC_EXTENSION)=.o)
OBJECTS_DIR = $(shell cd ../obj/$(CONFIG_NAME) && dirs -l)
INCLUDE_DIR = $(shell cd ../include && dirs -l)
DEPENDENCIES_DIR = $(shell cd ../dependencies && dirs -l)
DEP_INCLUDE_DIR = $(DEPENDENCIES_DIR)/include
DEP_LIBRARIES_DIR = $(DEPENDENCIES_DIR)/lib
BINARIES_DIR = $(shell cd ../bin/$(CONFIG_NAME) && dirs -l)
DEPENDENCIES = $(foreach dep, $(OBJECTS), $(OBJECTS_DIR)/$(dep))
CFLAGS = $(MODE) -Wall -march=$(ARCH) -mtune=$(ARCH) -I$(INCLUDE_DIR) -I$(DEP_INCLUDE_DIR) `pkg-config --cflags glib-2.0 gmodule-2.0`
LDFLAGS = -L$(DEP_LIBRARIES_DIR) -lglut -lIL -lILU -lILUT `pkg-config --libs glib-2.0 gmodule-2.0`
CLEAN_COMMAND = rm -f *.o *~ *.bak $(BINARY_NAME)

.$(SRC_EXTENSION).o:
	$(CC) $(CFLAGS) -c $< -o $@

all:
	-@ make create-links
	-@ make $(BINARIES_DIR)/$(BINARY_NAME)
	-@ make remove-links

create-links:
	-@ $(foreach file, $(SOURCES), $(shell ln -fs $(SOURCES_DIR)/$(file) $(OBJECTS_DIR)/$(file)))

remove-links:
	-@ rm -rf $(OBJECTS_DIR)/*.$(SRC_EXTENSION)

$(BINARIES_DIR)/$(BINARY_NAME): $(DEPENDENCIES)
	$(CC) $(DEPENDENCIES) $(LDFLAGS) -o $(BINARIES_DIR)/$(BINARY_NAME)

clean:
	-@ $(CLEAN_COMMAND)
	-@ cd ../ && $(CLEAN_COMMAND)
	-@ cd ../bin/ && $(CLEAN_COMMAND)
	-@ make clean_bin CONFIG_NAME=release
	-@ make clean_bin CONFIG_NAME=release SUFIX=.a
	-@ make clean_bin CONFIG_NAME=debug
	-@ make clean_bin CONFIG_NAME=debug SUFIX=.a
	-@ cd ../obj/debug/ && $(CLEAN_COMMAND)
	-@ cd ../obj/release/ && $(CLEAN_COMMAND)
	-@ cd ../src/ && $(CLEAN_COMMAND)
	-@ cd ../include/ && $(CLEAN_COMMAND)
	-@ make remove-links CONFIG_NAME=release
	-@ make remove-links CONFIG_NAME=debug

clean_bin:
	-@ cd ../bin/debug/ && $(CLEAN_COMMAND)
	-@ cd ../bin/release/ && $(CLEAN_COMMAND)

release:
	-@ make depend CONFIG_NAME=release SHARED_LIB_FLAGS= SHARED_SRC_FLAGS= PREFIX= SUFIX=
	-@ make CONFIG_NAME=release MODE=-O2 SHARED_LIB_FLAGS= SHARED_SRC_FLAGS= PREFIX= SUFIX=

debug:
	-@ make depend CONFIG_NAME=debug SHARED_LIB_FLAGS= SHARED_SRC_FLAGS= PREFIX= SUFIX=
	-@ make CONFIG_NAME=debug MODE=-g SHARED_LIB_FLAGS= SHARED_SRC_FLAGS= PREFIX= SUFIX=

depend:
	-@ cd $(SOURCES_DIR) && makedepend -Y *.$(SRC_EXTENSION) -I$(INCLUDE_DIR) -p$(OBJECTS_DIR)/ -f$(SCRIPTS_DIR)/Makefile
# DO NOT DELETE

/home/pedro/google/code/gluco/trunk/obj/debug/main.o: /home/pedro/google/code/gluco/trunk/include/window.h
/home/pedro/google/code/gluco/trunk/obj/debug/main.o: /home/pedro/google/code/gluco/trunk/include/util.h
/home/pedro/google/code/gluco/trunk/obj/debug/main.o: /home/pedro/google/code/gluco/trunk/include/window_manager.h
/home/pedro/google/code/gluco/trunk/obj/debug/main.o: /home/pedro/google/code/gluco/trunk/include/keyboard.h
/home/pedro/google/code/gluco/trunk/obj/debug/window.o: /home/pedro/google/code/gluco/trunk/include/window.h
/home/pedro/google/code/gluco/trunk/obj/debug/window.o: /home/pedro/google/code/gluco/trunk/include/util.h
/home/pedro/google/code/gluco/trunk/obj/debug/window_manager.o: /home/pedro/google/code/gluco/trunk/include/window_manager.h
/home/pedro/google/code/gluco/trunk/obj/debug/window_manager.o: /home/pedro/google/code/gluco/trunk/include/keyboard.h
/home/pedro/google/code/gluco/trunk/obj/debug/window_manager.o: /home/pedro/google/code/gluco/trunk/include/util.h
/home/pedro/google/code/gluco/trunk/obj/debug/window_manager.o: /home/pedro/google/code/gluco/trunk/include/window.h
